
#include "include.h"

//variable declarations
int intensity1, intensity2, light_intensity1, light_intensity2, light, MIN_intensity1 = 0,
MIN_intensity2 = 0, counting = 0, inout = 0, counter = 0, light_control = 1, shalarm = 1,
light1 = 0, light2 = 0, lvl = 0, shwd = 0;

double temperatur;


PROGRAM_INIT

	ACTIVATE_LCD
	CLEAR_LCD
	DDRB = DDRB | 0b00000111;
	PORTB = PORTB & 0b11111000;
	BEEP_VOLUME(100)
	pre_configuration();
	
PROGRAM_START

	switch(lvl){
		case 0:
			messages();
			person_counter();
			if(btn_center)
			{
				while(btn_center);
				lvl = 1;
				shwd = 0;
			}
			counting++;
			if(counting >= 1000000){
				lvl = 17;
				counting = 0;
			}
		break;
		case 1:
			messages();
			if(btn_down || btn_up)
			{
				lvl = 2;
				while(btn_down || btn_up);
				shwd = 0;
			}
			if(btn_right)
			{
				while(btn_right);
				lvl = 3;
				shwd = 0;
			}
			if(btn_center){
				while(btn_center);
				lvl = 0;
				shwd = 0;
			}
		break;
		case 2:
			messages();
			if(btn_down || btn_up)
			{
				lvl = 1;
				while(btn_down || btn_up);
				shwd = 0;
			}
			if(btn_right){
				while(btn_right);
				lvl = 8;
				shwd = 0;
			}
			if(btn_center){
				while(btn_center);
				lvl = 0;
				shwd = 0;
			}
		break;	
		case 3:
			messages();
			if(btn_down || btn_up){
			
				lvl = 4;
			
				while(btn_down || btn_up);
				shwd = 0;
			}
			if(btn_right){
				while(btn_right);
				lvl = (pattern())? 5 : 12;		//If pattern is right, alarm mode, else alarm is switched on
				shwd = 0;
			}
			if(btn_center){
				while(btn_center);
				lvl = 0;
				shwd = 0;
			}
		break;
		case 4:
			messages();
			if(btn_down || btn_up){
			
				lvl = 3;
			
				while(btn_down || btn_up);
				shwd = 0;
			}
			if(btn_right){
				while(btn_right);
				lvl = pattern()? 6 : 12;			//If pattern is right, normal mode, else alarm is switched on
				shwd = 0;
			}
			if(btn_center){
				while(btn_center);
				lvl = 0;
				shwd = 0;
			}
		break;
		case 5:
			messages();
			WAIT_SEC(3)
			lvl = 7;
			shwd = 0;
		break;
		case 6:
			messages();
			WAIT_SEC(3)
			lvl = 0;
			shwd = 0;
		break;
		case 7:
			messages();
			person_counter();
			if(counter > 0)							// When counter increases, alarm is turned ON
			{
				while(!(btn_center))
				{
					alarm();
				}
			}
			if(btn_center){
				while(btn_center);
				lvl = (pattern())? 6 : 12;				//If pattern is right, normal mode, else alarm is switched on
				shwd = 0;
			}
		break;
		case 8:
			messages();
			if(btn_down || btn_up){
			
				lvl = (btn_down)? 9 : 16;
			
				while(btn_down || btn_up);
				shwd = 0;
			}
			if(btn_right){
				while(btn_right);
				lvl = 10;
				shwd = 0;
			}
			if(btn_center){
				while(btn_center);
				lvl = 0;
				shwd = 0;
			}
		break;
		case 9:
			messages();
			if(btn_down || btn_up){
			
				lvl = (btn_down)? 16 : 8;
			
				while(btn_down || btn_up);
				shwd = 0;
			}
			if(btn_right){
				while(btn_right);
				lvl = 10;
				shwd = 0;
			}
			if(btn_center){
				while(btn_center);
				lvl = 0;
				shwd = 0;
			}
		break;
		case 10:
			messages();
			WAIT_SEC(3)
			lvl = 0;
			shwd = 0;
		break;
		case 16:
			messages();
			illumination_control();
			if(btn_down || btn_up){
			
				lvl = (btn_down)? 8 : 9;
			
				while(btn_down || btn_up);
				shwd = 0;
			}
			if(btn_center){
				while(btn_center);
				lvl = 0;
				shwd = 0;
			}
		break;
		case 11:
			messages();
			if(btn_center){
				while(btn_center);
				lvl = 14;
				shwd = 0;
			}
			if(btn_right){
				while(btn_right);
				lvl = 12;
				shwd = 0;
			}
		break;
		case 12:
			messages();
			WAIT_SEC(3)
			lvl = 13;
			shwd = 0;
		break;
		case 13:
			messages();
			if(btn_center){
				while(btn_center);
				lvl = 0;
				shwd = 0;
			}
		break;
		case 14:
			messages();
			WAIT_SEC(3)
			lvl = 0;
			shwd = 0;
		break;
		case 17:
			messages();
			person_counter();
			if(btn_center)
			{
				while(btn_center);
				lvl = 1;
				shwd = 0;
			}
			counting++;
			if(counting >= 1000000){
				lvl = 15;
				counting = 0;
			}
		break;
		case 15:
			messages();
			person_counter();
			if(btn_center)
			{
				while(btn_center);
				lvl = 1;
				shwd = 0;
			}
			counting++;
			if(counting >= 1000000){
				lvl = 18;
				counting = 0;
			}
		break;
		case 18:
			messages();
			person_counter();
			if(btn_center)
			{
				while(btn_center);
				lvl = 1;
				shwd = 0;
			}
			counting++;
			if(counting >= 1000000){
				lvl = 0;
				counting = 0;
			}
		break;

	}


PROGRAM_END

